/* 请求模块 */
import axios from "axios";

import store from "@/store";

const request = axios.create({
  baseURL: "http://api-toutiao-web.itheima.net",
});

export default request;

// 添加请求拦截器
request.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  const { user } = store.state
  if (user && user.token) {
    console.log(user);
    console.log(config);
    config.headers.Authorization = `Bearer ${user.token}`
  }
  return config;
}, function (error) {
  // 对请求错误做些什么
  return Promise.reject(error);
});
